<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <todo-list></todo-list>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        Vue.component("todo-item", {
            props: {
                title: String,
                del: {
                    type: Boolean,
                    default: false
                }
            },
            template:`
                <li>
                    <span v-if="!del">{{title}}</span>
                    <span v-else style="text-decoration: line-through">{{title}}</span>
                    <!-- 绑定事件 -->
                    <button v-show="!del" @click="handleClick">删除</button>
                </li>
            `,
            data: function() {
                return {}
            },
            methods:{
                handleClick() {
                    console.log("点击删除按钮")
                    // 把delete事件抛给父组件，在父组件中捕获@delete事件
                    this.$emit("delete", this.title)
                }
            },
        })
        Vue.component("todo-list", {
            template:`
                <ul>
                    <todo-item @delete="handleDelete" v-for="item in list" :title="item.title" :del="item.del"></todo-item>
                </ul>
            `,
            data: function(){
                return {
                    list:[
                        {
                            title: "课程1",
                            del: false
                        },
                        {
                            title: "课程2",
                            del: true
                        }
                    ]
                }
            },
            methods: {
                handleDelete(val) {
                    console.log("handleDelete", val)
                }
            }
        })
        var vm = new Vue({
            el: "#app",
            data: {}
        })
    </script>
</body>
</html>